<?php

namespace app\home\model;

use think\Model;

class TradeLog extends Model
{
    protected $table = 'tradelog';
    protected $connection = 'db_config2';

    const PAY_STATUS_UNPAID= 0;
    const PAY_STATUS_PAID = 1;

    /**
     * 获取时间范围内的充值总额
     * @param $user_id
     * @param $start_time
     * @param $end_time
     * @return float|int|string|null
     */
    public function getAmountByTime($user_id,$start_time,$end_time){
        return self::where('paydate','between',[$start_time,$end_time])
            ->where('status',self::PAY_STATUS_PAID)
            ->where('userid',$user_id)
            ->sum('amount');
    }

    public static function getChannelId($user_id){
        return db('accounts_info','db_config2')->where('UserID',$user_id)->value('SpreaderID');
    }

}